package lfp.addressselector.ui;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.TextView;

import lfp.addressselector.AddressSelectorHelper;
import lfp.addressselector.R;
import lfp.addressselector.widget.MapsView;

/**
 * Created by Administrator on 2017/6/6.
 */

public class AddressSelectActivity extends AppCompatActivity implements View.OnClickListener {
    private static final String KEY_LEVEL = "SELECTED_LEVEL";

    public static final void start(Activity activity, AddressSelectorHelper.ScopeLevel level, int ResultCode) {
        Intent intent = new Intent(activity, AddressSelectActivity.class);
        intent.putExtra(KEY_LEVEL, level);
        activity.startActivityForResult(intent, ResultCode);
    }

    AddressSelectorHelper.ScopeLevel mLevel;

    TextView tv_SelectedAddrInfo, tv_Commit;
    MapsView mMapsView;


    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.layout_address_select_activity);
        init();

    }

    void init() {
        Object level = getIntent().getSerializableExtra(KEY_LEVEL);
        mLevel = level == null ? AddressSelectorHelper.ScopeLevel.County : (AddressSelectorHelper.ScopeLevel) level;

        findViewById(R.id.view_Back).setOnClickListener(this);
        tv_SelectedAddrInfo = (TextView) findViewById(R.id.view_SelectedAddrInfo);
        tv_Commit = (TextView) findViewById(R.id.view_Commit);
        mMapsView = (MapsView) findViewById(R.id.view_MapsView);

    }

    @Override
    protected void onDestroy() {
        super.onDestroy();
        mMapsView.recycle();
    }

    @Override
    public void onClick(View view) {
        if (view.getId() == R.id.view_Back) {
            setResult(RESULT_CANCELED);
            finish();
        }
    }


}
